class Contract {
  int id;
  int app_id;
  int user_id;
  //合约类型：1免费合约，2广告合约，3签到合约，4VIP合约，5邀请合约
  int type;
  int hours;
  double hashrate;
  double? coin;
  int? checkin_detail_id;
  int? ad_video_id;
  String contract_start_at;
  String contract_end_at;
  //合约状态：0未开始，1已开始，2已结束
  int status;
  String created_at;
  String updated_at;

  Contract({
    required this.id,
    required this.app_id,
    required this.user_id,
    required this.type,
    required this.hours,
    required this.hashrate,
    this.coin,
    this.checkin_detail_id,
    this.ad_video_id,
    required this.contract_start_at,
    required this.contract_end_at,
    required this.status,
    required this.created_at,
    required this.updated_at,
  });

  factory Contract.fromJson(Map<String, dynamic> json) {
    return Contract(
      id: json['id'],
      app_id: json['app_id'],
      user_id: json['user_id'],
      type: json['type'],
      hours: json['hours'],
      hashrate: json['hashrate'].toDouble(),
      coin: json['coin']?.toDouble() ?? 0.0,
      checkin_detail_id: json['checkin_detail_id'] ?? 0,
      ad_video_id: json['ad_video_id'] ?? 0,
      contract_start_at: json['contract_start_at'],
      contract_end_at: json['contract_end_at'],
      status: json['status'],
      created_at: json['created_at'],
      updated_at: json['updated_at'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'app_id': app_id,
      'user_id': user_id,
      'type': type,
      'hours': hours,
      'hashrate': hashrate,
      'coin': coin ?? 0.0,
      'checkin_detail_id': checkin_detail_id ?? 0,
      'ad_video_id': ad_video_id ?? 0,
      'contract_start_at': contract_start_at,
      'contract_end_at': contract_end_at,
      'status': status,
      'created_at': created_at,
      'updated_at': updated_at,
    };
  }
}
